package com.ruoyi.web.controller.system;


import cn.hutool.core.util.StrUtil;
import com.ruoyi.common.core.page.ResponseResult;
import com.ruoyi.common.enums.ChannelEnum;
import com.ruoyi.system.ali.ChannelService;
import com.ruoyi.system.domain.Cash;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Api(tags = "管理后台:通道接口")
@RestController
@RequestMapping("/admin/channel")
public class AdminChannelController extends AdminController {

    private ChannelService channelService;


    @ApiOperation(value = "用户通道列表", notes = "type=auto 自动回调")
    @GetMapping("list")
    public ResponseResult<List<Cash>> list(String type) {
        List<ChannelCodeVo> list = this.listAll();
        if (StrUtil.equals(type, "auto")) {//平台操作的订单通道
            return this.setSuccessResult(this.listAuto());
        } else if (StrUtil.equals(type, "hand")) { //会员操作的订单通道
            List<ChannelCodeVo> channelCodeVos = this.listAuto();
            list.removeAll(channelCodeVos);
//            return this.setSuccessResult(list);
        } else {//所有通道

        }
        return this.setSuccessResult(list);
    }

    private List<ChannelCodeVo> listAll() {
        List<ChannelCodeVo> list = new ArrayList<>();
        for (ChannelEnum item : ChannelEnum.values()) {
            ChannelCodeVo channelCodeVo = new ChannelCodeVo();
            channelCodeVo.setChannelCode(item.getCode());
            channelCodeVo.setChannelName(item.getName());
            list.add(channelCodeVo);
        }
        return list;
    }

    private List<ChannelCodeVo> listAuto() {
        List<ChannelCodeVo> list = new ArrayList<>();
        for (ChannelEnum item : ChannelEnum.values()) {
            ChannelCodeVo channelCodeVo = new ChannelCodeVo();
            if (StrUtil.equals(item.getCode(), ChannelEnum.H5.getCode()) ||
                    StrUtil.equals(item.getCode(), ChannelEnum.FACE.getCode())
            ) {
                channelCodeVo.setChannelCode(item.getCode());
                channelCodeVo.setChannelName(item.getName());
                list.add(channelCodeVo);
            }


        }
        return list;
    }

    @Data
    class ChannelCodeVo {
        private String channelCode;

        private String channelName;
    }


}
